//
//  CellViewControllerForLabelAndTextField.m
//  MemoryTasks
//
//  Created by Philippe Bouamriou on 15/05/10.
//  Copyright 2010 Philippe Bouamriou. All rights reserved.
//

#import "CellViewControllerForLabelAndTextField.h"
#import "CellViewControllerForLabelAndTextField-IB.h"

@implementation CellViewControllerForLabelAndTextField

@synthesize delegate, _label, _textField, labelText, valueText, indicationText;

// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
   _label.text = labelText;
   _textField.text = valueText;
   _textField.placeholder = indicationText;
   [super viewDidLoad];
}

- (void)didReceiveMemoryWarning {
   // Releases the view if it doesn't have a superview.
   [super didReceiveMemoryWarning];
   
   // Release any cached data, images, etc that aren't in use.
}

- (void)viewDidUnload {
   [super viewDidUnload];
   // Release any retained subviews of the main view.
   // e.g. self.myOutlet = nil;
   self._textField = nil;
   self._label = nil;
}



#pragma mark -
#pragma mark Mutators

- (void)setIndicationText:(NSString *)theIndicationText {
   if (theIndicationText != indicationText) {
      indicationText = theIndicationText;
      _textField.placeholder = indicationText;
   }
}

- (void)setLabelText:(NSString *)theLabelText {
   if( theLabelText != labelText) {
      labelText = theLabelText;
      _label.text = labelText;
   }
}

- (void)setValueText:(NSString *)theValueText {
   if (theValueText != valueText) {
      valueText = theValueText;
      _textField.text = valueText;
   }
}

#pragma mark -
#pragma mark Custom Methods (Public)

- (void)resignFirstResponderForAllControls {
   [_textField resignFirstResponder];
}


- (void)becomeFirstResponder {
   [_textField becomeFirstResponder];
}

#pragma mark -
#pragma mark Actions

- (IBAction)textFieldEditingChanged:(id)sender {
   UITextField *theTextField = sender;
   if ([delegate respondsToSelector:@selector(cellViewController:textFieldEditingChanged:)]) {
      [delegate cellViewController:self textFieldEditingChanged:theTextField];
   }
}

- (IBAction)textFieldDidEndOnExit:(id)sender {
   UITextField *theTextField = sender;
   if ([delegate respondsToSelector:@selector(cellViewController:textFieldDidEndOnExit:)]) {
      [delegate cellViewController:self textFieldDidEndOnExit:theTextField];
   }
}

@end


